package com.microservice.postservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.microservice.commonutils.userVo.UserInfoVo;
import com.microservice.postservice.client.UserInfoClient;
import com.microservice.postservice.entity.PostComment;
import com.microservice.postservice.entity.PostContent;
import com.microservice.postservice.entity.PostImage;
import com.microservice.postservice.entity.vo.PostCommentVo;
import com.microservice.postservice.entity.vo.PostContentImageVo;
import com.microservice.postservice.mapper.PostCommentMapper;
import com.microservice.postservice.service.PostCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.microservice.postservice.service.PostContentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author leesin
 * @since 2022-05-14
 */
@Service
public class PostCommentServiceImpl extends ServiceImpl<PostCommentMapper, PostComment> implements PostCommentService {
    @Autowired
    PostCommentService postCommentService;
    @Autowired
    UserInfoClient userInfoClient;
    @Override
    /**
     * 获取评论和评论用户信息
     */
    public List<PostCommentVo> getPostComment(String postId) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("post_id",postId);
        List<PostComment> list = postCommentService.list(wrapper);

        //最终输出list
        List<PostCommentVo> postCommentVoList=new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            PostComment postComment= list.get(i);
            PostCommentVo postCommentVo =new PostCommentVo();

            BeanUtils.copyProperties(postComment,postCommentVo);
            //根据用户id获取用户信息
            String userId = postComment.getUserId();
            UserInfoVo userInfoVo=  userInfoClient.getUserInfoById(userId);

            postCommentVo.setUserInfoVo(userInfoVo);


            BeanUtils.copyProperties(postComment,postCommentVo);
            postCommentVoList.add(postCommentVo);
        }
        return postCommentVoList;
    }
}
